import { ok, fail } from '../utils/response'
import storeShopPrinterRepository, { StoreShopPrinterRow } from '../database/repositories/storeShopPrinterRepository'
import storeShopPrinterSettingRepository, { StoreShopPrinterSettingRow } from '../database/repositories/storeShopPrinterSettingRepository'
import storeShopComputerRepository, { StoreShopComputerRow } from '../database/repositories/storeShopComputerRepository'

/**
 * 设备域服务（仅保留“批量新增/更新”能力）
 * - printer：门店打印机
 * - computer：门店电脑
 */
export class DeviceDomainService {
    /** 批量新增/更新 打印机 */
    static printerBatchUpsert(rows: StoreShopPrinterRow[]) {
        try {
            storeShopPrinterRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            return fail(e?.message || 'printer batch upsert failed')
        }
    }

    /** 批量新增/更新 电脑 */
    static computerBatchUpsert(rows: StoreShopComputerRow[]) {
        try {
            storeShopComputerRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            return fail(e?.message || 'computer batch upsert failed')
        }
    }

    /** 批量新增/更新 打印机设置 */
    static printerSettingBatchUpsert(rows: StoreShopPrinterSettingRow[]) {
        try {
            storeShopPrinterSettingRepository.upsertBatch(rows)
            return ok(true)
        } catch (e: any) {
            console.error(e)

            return fail(e?.message || 'printer setting batch upsert failed')
        }
    }
}

export default DeviceDomainService


